// 加密解密套件
import CryptoJS from 'crypto-js'
let pwd = 'ABCDEFGHIJKLMNww'
let check = '12345678qwerty'
const crypto = {
    //解密
    Decrypt(word: any) { 
        word = word+"";
        let key = CryptoJS.enc.Base64.parse(pwd);
        let iv = CryptoJS.enc.Base64.parse(check);
        // 返回的是一个Word Array Object，其实就是Java里的字节数组
        let decrypted = CryptoJS.AES.decrypt(word, key, {
            iv: iv,
            mode: CryptoJS.mode.ECB,
            padding: CryptoJS.pad.Pkcs7,
        });
        return decrypted.toString(CryptoJS.enc.Utf8); 
    },
    //加密
    Encrypt(word: any) {
        word = word+"";
        let key = CryptoJS.enc.Base64.parse(pwd);
        let iv = CryptoJS.enc.Base64.parse(check);
        let encrypted = CryptoJS.AES.encrypt(word, key, {
            iv: iv,
            mode: CryptoJS.mode.ECB,
            padding: CryptoJS.pad.Pkcs7,
        });
        // 这里的encrypted不是字符串，而是一个CipherParams对象
        return encrypted.ciphertext.toString(CryptoJS.enc.Base64); 
    }
}
export default crypto
